﻿using DeviceMaintainGIS.Model;
using DeviceMaintainGIS.Model.Field;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using static DeviceMaintainGIS.Model.Field.FieldRequest;
using DeviceMaintainGIS.BLL.Field;
using System.Web.Script.Serialization;
using DeviceMaintainGIS.Common;

namespace DeviceMaintainGIS.Controllers
{
    /// <summary>
    /// 现场服务操作
    /// </summary>
    public class FieldHandleController : ApiController
    {
        /// <summary>
        /// 根据条件查询现场服务信息
        /// </summary>
        /// <returns></returns>
        public ReturnListVM<FieldResponse> Get([FromUri]FieldSelectRequest request)
        {
            return new FieldService().GetFieldList(request);
        }

        /// <summary>
        /// 添加或编辑现场服务信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        // POST: api/FieldHandle
        public ReturnMessageVM Post([FromBody]FieldRequest request)
        {
            JavaScriptSerializer jsonSerialize = new JavaScriptSerializer();
            String strJson = jsonSerialize.Serialize(request);//输出结果：{"Id":1,"UserName":"张三","Time":"\/Date(1297950721668)\/"}
            string pars = string.Format("现场服务信息提交或保存请求：\r\n 时间 = {0};\r\n 参数 = {1};"
            , System.DateTime.Now
            , strJson);
            LogHelper.WriteLog(typeof(FilterConfig), pars);
            return new FieldService().FieldOperation(request);
        }

    }
}
